package vorlesung2510

object ex2 {
  def main(args: Array[String]): Unit = {
    println(sum(4, 5, 6, 7, 8, 9, 1, 2))
    val arr = Array(1, 2, 3)
    var temp = List[Int]()
    println(sum(arr: _*))
    println(sum2(4, 5, 6, 7, 8, 9, 1, 2))
    println(sum2(arr: _*))
    println(sum3(4, 5, 6, 7, 8, 9, 1, 2))
    println(sum3(arr: _*))
    println(average(1.0,2.0,3.0,4.0))
  }
// mit var
  def sum(is: Int*) = {
    var ans = 0
    for (i <- is)
      ans += i
    ans
  }
// ohne var
  def sum2(is: Int*) = {
    is.foldLeft(0)((s, i) => s + i)
  }
// als Funktion
  val sum3: (Int*) => Int = is => is.foldLeft(0)((s, i) => s + i)
  
  def average(ds:Double*)= ds.foldLeft(0.0)((s,i)=>s+i) / ds.size
  
  val average2: (Double*) => Double= ds => ds.foldLeft(0.0)((s,i)=>s+i) / ds.size
}
